﻿<!DOCTYPE html>
<html lang="en">
<head>
    <title>权限编辑</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="${base}/res/plugin/ztree/css/style.css" type="text/css">
    <link href="${base}/res/manage/css/common.css" rel="stylesheet">
    <link href="${base}/res/manage/css/ec.css" rel="stylesheet">
    <link href="${base}/res/manage/css/list.css" rel="stylesheet">
    <script type="text/javascript" src="${base}/static/res/plugin/jquery/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="${base}/static/res/plugin/validator/jquery.validate.min.js"></script>
    <script type="text/javascript" src="${base}/static/res/plugin/ztree/js/jquery.ztree.core-3.5.min.js"></script>
    <script type="text/javascript" src="${base}/static/res/plugin/ztree/js/jquery.ztree.excheck-3.5.min.js"></script>
    <script type="text/javascript" src="${base}/static/res/plugin/ztree/js/jquery.ztree.exedit-3.5.min.js"></script>
    <script type="text/javascript" src="${base}/static/res/util/utils.js"></script>
    <script type="text/javascript" src="${base}/static/res/admin/js/common.js"></script>
    <script type="text/javascript" src="${base}/static/res/util/areaSelUtil.js"></script>
[#include "/admin/include/plupload.ftl" /]
    <script type="text/javascript">
        //加载树形
        $(document).ready(function () {
            //展现树形选择
            $("#parentName").focus(function () {
                var areaSel = new MenuSelUtil({
                    webPath: '${base}',
                    cid: '#id',
                    id: '#parentId',
                    name: '#parentName',
                    activeId: 'parentName'
                });
                areaSel.showTree();
            });

            //清空父区域
            $("#clearParentArea").click(function () {
                $("#parentId").val("");
                $("#parentName").val("");
            });

            //表单验证，数据提交
            $("#inputForm").validate({
                rules: {
                    name: {
                        required: true,
                        maxlength: "200"
                    },
                    orders: {
                        required:true,
                        digits: true,
                        min: 0
                    },
                    remark: {
                        maxlength: "50"
                    },
                    type: {
                        required: true
                    }
                },
                messages: {
                    name: {
                        required: "必填项",
                        maxlength: "最长200个字符"
                    },
                    orders: {
                        required:"必填项",
                        min: "最小为0",
                        digits: "必须为数字"
                    },
                    remark: {
                        maxlength: "最长50个字符"
                    },
                    type: {
                        required: "必选项"
                    }
                },
                submitHandler: function (form) {

                    var at = $("#inputForm").attr("action");
                    if (at == "update.jhtml" && $("#id").val() == "") {
                        alert("未能获取将要修改对象的ID!");
                        return false;
                    }

                    $(form).find(":submit").prop("disabled", true);
                    //异步提交更新
                    $.post($("#inputForm").attr("action"), $("#inputForm").serialize(), function (data) {
                        $(form).find(":submit").prop("disabled", false);
                        $.message(data.type, data.msg);
                        if (data.success) {
                            var o = data.data;
                            //强制刷新异步树形节点
                            var treeObj = parent.$.fn.zTree.getZTreeObj("treeDemo");
                            var tNode = treeObj.getNodeByParam("com.project.common.web.utils.id", com.project.common.web.utils.id, null);
                            var opNode = treeObj.getNodeByParam("com.project.common.web.utils.id", o.parentId, null);
                            if (!tNode) {
                                if (opNode) {
                                    opNode.isParent = true;
                                    treeObj.reAsyncChildNodes(opNode, "refresh");
                                } else if (!o.parentId) {
                                    treeObj.reAsyncChildNodes(null, "refresh");
                                }

                            } else if (o.parentId && tNode.parentId) {

                                opNode = treeObj.getNodeByParam("com.project.common.web.utils.id", o.parentId, null);
                                if (opNode) {
                                    opNode.isParent = true;
                                    treeObj.reAsyncChildNodes(opNode, "refresh");
                                }

                                if (o.parentId != tNode.parentId) {
                                    var tpNode = treeObj.getNodeByParam("com.project.common.web.utils.id", tNode.parentId, null);
                                    if (tpNode) {
                                        tpNode.isParent = true;
                                        treeObj.reAsyncChildNodes(tpNode, "refresh");
                                    }
                                }

                            } else {
                                treeObj.reAsyncChildNodes(null, "refresh");

                            }
                            //表单回填
                            fillObjToForm(o, "#inputForm");
                        }

                    });

                }
            });

            var up = extPlupload("${base}", {});
            var up = extPlupload("${base}", {btn: "pickfiles_bg",fieldId: "fileName_bg"});
        });
    </script>
</head>
<body>
[#--主体--]
<div class="tab set">
    <div class="tablist message set">
        <form id="inputForm" action="update.jhtml" method="post" name="inputForm">
        [#--隐藏字段--]
            <input name="parentId" id="parentId" value="${menu.parentId}" type="hidden"/>
            <input name="id" id="id" value="${menu.id}" type="hidden"/>
            <table cellpadding="0" cellspacing="0">
                <tr>
                    <td><label>菜单名称<span class="cred"> * </span></label></td>
                    <td>
                        <input type="text" id="name" name="name" value="${menu.name}" placeholder="菜单名称">
                    </td>

                    <td><label>父级菜单</label></td>
                    <td>
                        <input type="text" id="parentName" name="parentName" class="uploadTxt" value="${menu.parentName}"
                               readonly="readonly" placeholder="请选择">
                        <input type="button" value="清空" id="clearParentArea" class="uploadBtn">
                    </td>
                </tr>

                <tr>
                    <td><label>菜单类型<span class="cred"> * </span></label></td>
                    <td>
                        <select id="type" name="type">
                            <option value="">请选择</option>
                        [@stdCode codeType="MENU_TYPE" all=false]
                            [#list codeMap.entrySet() as entry]
                                <option value="${entry.key}"
                                        [#if entry.key == menu.type]selected="selected"[/#if]>${entry.value}</option>
                            [/#list]
                        [/@stdCode]
                        </select>
                        <a href="javascript:;" class="arrows">∨</a>
                    </td>

                    <td><label>URL</label></td>
                    <td>
                        <input type="text" id="url" name="url" value="${menu.url}" placeholder="URL">
                    </td>
                </tr>

                <tr>
                    <td><label>描述</label></td>
                    <td>
                        <input type="text" id="remark" name="remark" value="${menu.remark}" placeholder="描述信息">
                    </td>

                    <td><label>排序<span class="cred"> * </span></label></td>
                    <td>
                        <input type="text" id="orders" name="orders" value="${menu.orders}" placeholder="排序">
                    </td>
                </tr>

                <tr>
                    <td><label>图片</label></td>
                    <td>
                        <input id="fileName" name="medium" type="text" class="uploadTxt" value="${menu.medium}"/>
                        <input id="pickfiles" type="button" value="上传" class="uploadBtn"/>
                    </td>

                    <td><label>背景图片</label></td>
                    <td>
                        <input id="fileName_bg" name="mediumBg" type="text" class="uploadTxt" value="${menu.mediumBg}"/>
                        <input id="pickfiles_bg" type="button" value="上传" class="uploadBtn"/>
                    </td>
                </tr>

            </table>
            <p class="save">
                <input type="submit" value="保存" class="red">
            </p>
        </form>
    </div>
</div>
</body>
</html>